import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import path from 'path';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],

  server: {
    proxy: {
      '/dev-api': {
        // target: 'http://smtshop.hwur.com/', //后台地址
        target: 'http://192.168.0.121:50000', //开发地址
        changeOrigin: true, //开启跨域
        rewrite: (path) => path.replace(/^\/dev-api/, ''),
      },
    },
  },

  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src'),
    },
  },
  configureWebpack: {
    module: {
      rules: [
        {
          test: /\.vue$/,
          use: [
            {
              loader: 'vue-loader',
              options: {
                compilerOptions: {
                  isCustomElement: (tag) => tag === 'VueReCaptcha', // 替换为您的自定义元素标签名
                },
              },
            },
          ],
        },
      ],
    },
  },
  build: {
    outDir: 'dist', // 指定输出目录
    assetsInlineLimit: 4096, // 内联资源大小限制（字节）
    sourcemap: true, // 生成 source map 用于调试
    minify: false, // 不开启代码压缩
    rollupOptions: {
      output: {
        manualChunks(id) {
          if (id.includes('node_modules')) {
            return id.toString().split('/')[1].toLowerCase();
          }
        },
      },
    },
    terserOptions: {
      compress: {
        drop_console: true, // 移除 console.log
      },
    },
  },
});
